// pages/index_city/index_city.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cityList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.getCity()
    this.dial()
  },
  getCity: function () {
    var _this = this
    wx.request({
      url: 'https://miniapp.odeman.com/summercamp/index_city.php',
      data: {},
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        if (res.data.status == "success") {
          _this.setData({
            cityList: res.data.list
          })
        }
      }
    })
  },
  about: function () {
    app.about()
  },
  //联系我们
  contact: function () {
    app.contact()
  },
  onShareAppMessage: function () {
    return {
      title: '奥德曼夏令营',
    }
  },
  getPhone:function() {
    wx.request({
      url: 'https://miniapp.odeman.com/summercamp/get_area_phone.php',
      data: {
        areaid: wx.getStorageSync('areaid')
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success(res) {
        wx.setStorageSync('phoneNumber', res.data.phone)
      }
    })
  },
  
  navTap: function (e) {
    var areaid = e.currentTarget.dataset.areaid;
    console.log(areaid)
    var cityName = e.currentTarget.dataset.cityname
    console.log(cityName)
    wx.setStorageSync('cityName', cityName)
    wx.setStorageSync('areaid', areaid)

    this.getPhone()
    wx.navigateTo({
      url: '../index_index/index_index'
    })
  },
  
  dial:function(){
    wx.request({
      url: 'https://miniapp.odeman.com/summercamp/get_area_phone.php', 
      data: {
        areaid: wx.getStorageSync('areaid')
      },
      header: {
        'content-type': 'application/json' 
      },
      success: function (res) {
        wx.setStorageSync('tel', res.data.phone)
      }
    })
  }

})